import requests, json, unittest

class Mock():

    global AccessToken

    def getToken(self, headers, data):
        '''登录成功后获取token'''
        global AccessToken
        url = 'http://uat-sj-gateway.aihuishou.com/sj-api/auth/login'
        r = requests.post(url, headers=headers, data=data)
        token = r.json()['data']['accessToken']
        print(token)
        AccessToken = token

    def test_search(self, headers):
        '''验证代拍单商品列表接口'''
        global AccessToken
        url='http://uat-sj-gateway.aihuishou.com/sj-api/supply-product/v2/detail/search'
        data={
            "supplyOrderNo": "S20190111200753075374",
            "pageSize": 20,
            "pageIndex": 0
        }
        headers['Access-Token'] = AccessToken
        print(headers)
        r = requests.post(url, headers=headers, json=data)
        print(r.json())


if __name__ == '__main__':
    headers = {"Version": "1450", "Platform": "ios", "Content-Type": "application/json"}
    data = {"userName":"18800000001","passWord":"qwer1234"}
    # print(type(data))
    data = json.dumps(data)
    # print(type(data1))
    Mock().getToken(headers, data)
    Mock().test_search(headers)
